/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-01-18
 * Time: 23:01
 */
public class SymmetryBinaryTree {
    //对称二叉树
    public static boolean isSymmetric(BinaryTree.TreeNode root) {
        if(root == null) {
            return true;
        }
        return isSymmetricChild(root.left,root.right);
    }
    public static boolean isSymmetricChild(BinaryTree.TreeNode leftTree, BinaryTree.TreeNode rightTree) {
        //1.结构上
        //1.1左为空右不为空或者左不为空右为空
        if(leftTree ==null && rightTree!=null || leftTree !=null && rightTree==null) {
            return false;
        }
        //1.2左右都为空
        if(leftTree == null && rightTree == null) {
            return true;
        }
        //2.值
        //2.1左右的值都不相同
        if(leftTree.val != rightTree.val) {
            return false;
        }
        //2.2左右的值都相同
        return isSymmetricChild(leftTree.left,rightTree.right) && isSymmetricChild(leftTree.right,rightTree.left);
    }
    
}
